{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h1><i class="bi bi-bookmark-star"></i> 知识点</h1>
            <a href="{{ url_for('index') }}" class="btn btn-secondary">
                <i class="bi bi-arrow-left"></i> 返回首页
            </a>
        </div>
        
        {% if knowledge_list %}
        <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
            {% for kp in knowledge_list|sort(attribute='count', reverse=true) %}
            <div class="col">
                <div class="card h-100">
                    <div class="card-body">
                        <h5 class="card-title">{{ kp.name }}</h5>
                        <p class="card-text">
                            <span class="badge bg-primary">相关错题: {{ kp.count }} 道</span>
                        </p>
                        
                        {% if kp.mistake_ids %}
                        <p class="card-text">
                            <small class="text-muted">
                                <i class="bi bi-list"></i> 相关题目: 
                                {% for mistake_id in kp.mistake_ids[:5] %}
                                    <a href="{{ url_for('view_mistake', mistake_id=mistake_id) }}" class="badge bg-secondary text-decoration-none">#{{ mistake_id }}</a>
                                {% endfor %}
                                {% if kp.mistake_ids|length > 5 %}
                                    <span class="badge bg-light text-dark">+{{ kp.mistake_ids|length - 5 }} 更多</span>
                                {% endif %}
                            </small>
                        </p>
                        {% endif %}
                    </div>
                    <div class="card-footer">
                        <small class="text-muted">
                            <i class="bi bi-bar-chart"></i> 占总错题 {{ (kp.count / (mistakes|length if mistakes else 1)) * 100 | round(1) }}%
                        </small>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <div class="alert alert-info text-center">
            <h4 class="alert-heading">暂无知识点记录</h4>
            <p>添加错题后，相关知识点会自动显示在这里。</p>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}